﻿@model thailandProject.Models.PagedList<thailandProject.Models.CLIENT>

@{
    ViewBag.Title = "Clients";
    int i = 1; // counter for number of iterations through clients
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <h1>Search/Add Clients</h1>
            <!-- CONTENT GOES HERE -->
            <!--<div id="searchcontainer">
                <input style="color:#999999;" id="searchclient" type="text" /><a href=""><img height="40px" alt="search" src="../../images/searchicon.png" /></a>
            </div>-->
            <div id="searchcontainer">
                @using (Html.BeginForm("Index", "Clients", FormMethod.Post, new { id = "clientSearch" }))
                {
                    if (Session["ClientDeleted"] != null && (bool)Session["ClientDeleted"] == true)
                    {
                        <span style="color:red;">The client has been deleted.</span>
                        <br /><br />
                    }
                    <input style="color:#999999;" id="searchclient" data-autocomplete="@Url.Action("QuickSearch", "clients")" name="clientName" type="text" />
                    <input type="image" alt="search" src="../../images/searchicon.png" />
                    <input type="hidden" id="formcheck" value="false" />
                }
                <br />
                @if (Model != null)
                {
                    <table cellspacing="0" cellpadding="5" id="searchclienttable">
                        <tr id="searchclienttoprow">
                            <th class="searchclientcols20">
                                @Html.ActionLink("First", "Index", new
                           {
                               pageNumber = ViewBag.PageNumber,
                               sortType = "clientFirstName"
                           })
                                @Html.ActionLink("Last", "Index", new
                           {
                               pageNumber = ViewBag.PageNumber,
                               sortType = "clientLastName"
                           })
                            </th>
                            <th class="searchclientcols20">
                                @Html.ActionLink("City", "Index", new
                           {
                               pageNumber = ViewBag.PageNumber,
                               sortType = "clientCity"
                           })
                            </th>
                            <th class="searchclientcols35">
                                @Html.ActionLink("Email", "Index", new
                           {
                               pageNumber = ViewBag.PageNumber,
                               sortType = "clientEmail"
                           })
                            </th>
                            <th style="width:5%;"><!-- View Column -->
                            </th>
                        </tr>
                        <tr>
                            <th colspan="5">
                                @if((int)Session["userPerm"] <= 2)
                                {
                                    @Html.ActionLink("(+) Add New Client...", "AddClient", null, new { @class = "addnewclient" })
                                }
                            </th>
                        </tr>
                        
                    @foreach (var client in Model)
                    {
                        //Ensure that Model isn't null. It will be null on the first load
                        // if odd row, keep same row color
                        if (thailandProject.Models.UtilMethods.isOdd(i))
                        {
                         <tr style="background:url('/images/transblack1.png') repeat scroll 0 0 transparent;" class="searchclientrow">
                        
                            <td style="border-bottom:1px dotted #cccccc; font-weight:bold;">
                                @Html.DisplayFor(modelItem => client.clientFirstName)
                                @Html.DisplayFor(modelItem => client.clientLastName)
                            </td>
                            <td style="border-bottom:1px dotted #cccccc">
                                @Html.DisplayFor(modelItem => client.clientCity)
                            </td>
                            <td style="border-bottom:1px dotted #cccccc">
                                @Html.Raw(thailandProject.Models.UtilMethods.stringWithBreak(client.clientEmail.ToString()))
                            </td>
                            <td style="text-align:right; border-bottom:1px dotted #cccccc;">
                                @{
                                    string view_link = "Clients/ViewClient?clientId=" + client.clientID;
                                    <a href="@view_link"><img src="../../images/viewclient_small_long.png" alt="view" /></a>
                                 }
                            </td>
                        </tr>
                        }
                        // if not odd row, then show a slight color change for better view
                        else 
                        {
                         <tr class="searchclientrow">
                        
                            <td style="border-bottom:1px dotted #cccccc; font-weight:bold;">
                                @Html.DisplayFor(modelItem => client.clientFirstName)
                                @Html.DisplayFor(modelItem => client.clientLastName)
                            </td>
                            <td style="border-bottom:1px dotted #cccccc">
                                @Html.DisplayFor(modelItem => client.clientCity)
                            </td>
                            <td style="border-bottom:1px dotted #cccccc">
                                @Html.Raw(thailandProject.Models.UtilMethods.stringWithBreak(client.clientEmail.ToString()))
                            </td>
                            <td style="text-align:right; border-bottom:1px dotted #cccccc;">
                                 @{
                                    string view_link = "Clients/ViewClient?clientId=" + client.clientID;
                                    <a href="@view_link"><img src="../../images/viewclient_small_long.png" alt="view" /></a>
                                 }
                            </td>
                        </tr>   
                        }
                        i++;
                    }
                        <!-- Prev Page -- Next Page -->
                        <tr>
                            <td colspan="4">
                                <table style="width:100%;">
                                    <tr>
                                        <td style="border-bottom:1px dotted #cccccc">
                                            @if (Model.hasPreviousPage)
                                            {
                                                @Html.ActionLink("< Prev", "Index", new
                                           {
                                               pageNumber = ViewBag.PageNumber - 1,
                                               sortType = ViewBag.SortType
                                           })
                                            }
                                            else
                                            {
                                                @Html.Raw("< Prev");
                                            }
                                        </td>
                                        <td style="border-bottom:1px dotted #cccccc; text-align:center">
                                            @for (int j = Model.pageMin; j <= Model.pageMax; j++)
                                            {
                                                if(j != Model.pageNumber)
                                                {
                                                    @Html.ActionLink(" " + j.ToString(), "Index", new
                                                    {
                                                        pageNumber = j,
                                                        sortType = ViewBag.SortType
                                                    })
                                                }
                                                else
                                                {
                                                    @(" " + j)
                                                }
                                            }
                                        </td>
                                        <td style="border-bottom:1px dotted #cccccc; text-align:right">
                                            @if (Model.hasNextPage)
                                            {
                                                @Html.ActionLink("Next >", "Index", new
                                           {
                                               pageNumber = ViewBag.PageNumber + 1,
                                               sortType = ViewBag.SortType
                                           })
                                            }
                                            else
                                            {
                                                @Html.Raw("Next >");
                                            }
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                }
            </div>
            <div>
                
            </div>
        </nav>
        
        <!-- Left column ends here -->
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        Search for a client by entering their name into the search box and pressing the magnifying glass icon.
        <br />To see all clients, do not enter anything and press the magnifying glass icon.
        <br /><br />
        View a client's details by pressing the page icon at the end of the row.
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script>
    $(document).ready(function () {
        $("#clientSubmit").submit(function () {
            if ($("#formcheck").val() == 'false') {
                $("#formcheck").val('true');
                return true;
            }
            else {
                alert('Your action is currently being processed. Please wait');
                return false;
            }
        });

    })
</script>

@*<script type="text/javascript">
    
</script>*@